const usercontrol = require("./userController");
const dbconfig = require("../util/dbconfig");

// 用户名，手机号登录
let phoneLogin = async (req, res) => {
    let { username, password } = req.query;
    console.log(username, password);
    // 判断手机号是否正确
    // (/^1[3456789]d{9}$/.test(username))
    if (username) {
        let sql = `select * from user where username=?`;
        let sqlArr = [username];
        let user = await dbconfig.asyncSqlconnect(sql, sqlArr);
        console.log("res", user);
        if (user.length) {
            if (password == user[0].password) {
                res.send({
                    code: 200,
                    msg: "用户名登录成功",
                    user: user,
                });
            } else {
                res.send({
                    code: 400,
                    msg: "密码错误",
                });
            }
        } else {
            res.send({
                code: 400,
                msg: "无此用户名",
            });
        }
    } else {
        res.send({
            code: 400,
            msg: "用户名格式错误",
        });
    }
};
module.exports = {
    phoneLogin,
};
